﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.SimulationSettings.CUiSimulationSettingsWindow
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands.SimulationSettings;

public class CUiSimulationSettingsWindow : TxWindow, IComponentConnector
{
  internal TxNumericEditBoxControl m_timeInterval;
  internal Label m_unitLabel;
  internal Slider m_slider;
  internal Button m_btnCancel;
  internal Button m_btnOK;
  private bool _contentLoaded;

  [DllImport("UiTasks.dll")]
  private static extern void DeactivateRealTimeSimulationMode();

  public CUiSimulationSettingsWindow() => this.InitializeComponent();

  private void TxWindow_Loaded(object sender, RoutedEventArgs e)
  {
    if (TxApplication.Options.Simulation.RealTimeSimulationMode)
      this.m_slider.Value = 50.0;
    else
      this.m_slider.Value = (double) TxApplication.Options.Simulation.SimulationSpeed;
    this.m_timeInterval.Value = CSISSimulationSettingsManager.SimulationTimeInterval;
    ((UIElement) this.m_timeInterval).IsEnabled = CSISSimulationSettingsManager.CanChangeTimeInterval;
    this.m_unitLabel.Content = (object) TxApplication.Options.Units.TimeUnitName;
  }

  private void m_btnOK_Click(object sender, RoutedEventArgs e)
  {
    int int32 = Convert.ToInt32(this.m_slider.Value);
    if (TxApplication.Options.Simulation.RealTimeSimulationMode)
    {
      if (int32 != 50)
      {
        TxApplication.Options.Simulation.SimulationSpeed = int32;
        CUiSimulationSettingsWindow.DeactivateRealTimeSimulationMode();
      }
    }
    else if (int32 != TxApplication.Options.Simulation.SimulationSpeed)
      TxApplication.Options.Simulation.SimulationSpeed = int32;
    if (this.m_timeInterval.Value != CSISSimulationSettingsManager.SimulationTimeInterval)
      CSISSimulationSettingsManager.SimulationTimeInterval = this.m_timeInterval.Value;
    ((Window) this).Close();
  }

  private void m_btnCancel_Click(object sender, RoutedEventArgs e) => ((Window) this).Close();

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/simulationsettings/cuisimulationsettingswindow.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        ((FrameworkElement) target).Loaded += new RoutedEventHandler(this.TxWindow_Loaded);
        break;
      case 2:
        this.m_timeInterval = (TxNumericEditBoxControl) target;
        break;
      case 3:
        this.m_unitLabel = (Label) target;
        break;
      case 4:
        this.m_slider = (Slider) target;
        break;
      case 5:
        this.m_btnCancel = (Button) target;
        this.m_btnCancel.Click += new RoutedEventHandler(this.m_btnCancel_Click);
        break;
      case 6:
        this.m_btnOK = (Button) target;
        this.m_btnOK.Click += new RoutedEventHandler(this.m_btnOK_Click);
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
